package com.dcivision.framework;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Locale;
import java.util.Properties;

import org.apache.struts.util.MessageResources;
import org.apache.struts.util.MessageResourcesFactory;

public class DcivisionMessageResources extends MessageResources {

    private static String messageFilePath = "/com/dcivision/resource/ApplicationResources.properties";

    public DcivisionMessageResources(MessageResourcesFactory factory, String arg1) {
        super(factory, arg1);

        Properties tt = new Properties();

        try {
            tt.load(DcivisionMessageResources.class.getResourceAsStream(messageFilePath));
        } catch (Exception exp) {
            TLog.log.error("Exception caught while loading message file=" + messageFilePath, exp);
        }

        formats = new HashMap();
        for (Iterator iter = tt.keySet().iterator(); iter.hasNext();) {
            String element = (String) iter.next();
            formats.put(element, tt.getProperty(element));
        }
    }

    public String getMessage(Locale locale, String key) {
        return (String) formats.get(key);
    }

    /**
     * @param messageFileAbsolutePath
     *            the messageFileAbsolutePath to set
     */
    public static void setMessageFileAbsolutePath(String messageFileAbsolutePath) {
        DcivisionMessageResources.messageFilePath = messageFileAbsolutePath;
    }

    /**
     * @return the messageFileAbsolutePath
     */
    public static String getMessageFileAbsolutePath() {
        return messageFilePath;
    }

}
